package com.cysyz.mylib.excel.engine.impl.poi2;

import java.text.DecimalFormat;

import org.apache.poi.hssf.usermodel.HSSFCell;

import com.cysyz.mylib.excel.engine.CellEngine;

public class CellEnginePoi2Impl implements CellEngine{
	private HSSFCell cell;
	
	public CellEnginePoi2Impl(HSSFCell cell) {
		super();
		this.cell = cell;
	}

	@Override
	public String getContents() {
		return this.getCellStringValue();
	}
	
	private String getCellStringValue() {
		String cellValue = null;
		DecimalFormat stringDf = new DecimalFormat("#########");
		switch (cell.getCellType()) {
		case HSSFCell.CELL_TYPE_STRING:
			cellValue = cell.getStringCellValue();
			break;
		case HSSFCell.CELL_TYPE_NUMERIC:
			cellValue = stringDf.format(cell.getNumericCellValue());
			break;
		case HSSFCell.CELL_TYPE_BLANK:
			break;
		}
		if (cellValue != null) {
			cellValue = cellValue.replaceAll(" ", "");
		}
		return cellValue;
	}
}
